# $Id$
# Maintainer: Sébastien Luttringer
# Contributor: Balwinder S "bsd" Dheeman (bdheeman AT gmail.com)

pkgname=dkms
pkgver=2.2.0.3
pkgrel=15
pkgdesc='Dynamic Kernel Modules System'
arch=('any')
url='http://linux.dell.com/dkms/'
license=('GPL2')
depends=('bash' 'kmod' 'gcc' 'make' 'patch')
optdepends=('linux-headers: build modules against Arch kernel'
            'linux-lts-headers: build modules against LTS Arch kernel')
backup=('etc/dkms/framework.conf' 'etc/default/dkms')
install=$pkgname.install
source=("http://linux.dell.com/$pkgname/permalink/$pkgname-$pkgver.tar.gz"
        "$pkgname.default"
        "$pkgname.service"
        "$pkgname.systemd"
        '01-broken-uninstall.patch'
        '02-no-kernel-hook.patch'
        '03-fix-post-build.patch')
md5sums=('11a8aaade2ebec2803653837c7593030'
         '33be2fbf1bcc1b3fb2f38d9e7eaa809d'
         '02e9744e3fdc3d2f68e46966fb32e260'
         '267632312aa52a190ec0db0758920dd3'
         '2dfd8656dc79afd229c1481a90fb645b'
         '82d520c39c99c34977e48b313a189c6c'
         'fd7cb2119954b3b9d760a8eebd3c583d')

prepare() {
  # patch
  patches=("$srcdir"/*.patch)
  cd $pkgname-$pkgver
  for p in "${patches[@]}"; do
    msg2 "Apply patch: ${p##*/}"
    patch -p1 -i "$p"
  done
  # /usr move
  msg2 '/usr move patching'
  for i in dkms{,_framework.conf,.bash-completion,.8,_common.postinst}; do
    sed -ri 's,/lib/modules,/usr/lib/modules,g' "$i"
  done
  # fix hardcoded paths
  sed -i "s|/sbin/depmod|depmod|" dkms
}

package() {
  # systemd
  install -D -m 644 $pkgname.service "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  install -D -m 755 $pkgname.systemd "$pkgdir/usr/lib/systemd/scripts/$pkgname"
  install -D -m 644 $pkgname.default "$pkgdir/etc/default/$pkgname"
  # upstream installer
  cd $pkgname-$pkgver
  make \
    DESTDIR="$pkgdir" \
    SBIN="$pkgdir/usr/bin" \
    BASHDIR="$pkgdir/usr/share/bash-completion/completions" \
    install
}

# vim:set ts=2 sw=2 et:
